package com.utils;

import com.exception.ApiException;

import java.util.Collection;

/**
 * Created by Administrator on 2018/12/22.
 */
public class MyAssert {
    public static <T> void assertNotEmpty(Collection<T> c, ApiException e) {
        if (c == null || c.isEmpty()) throw e;
    }

    public static void assertNotEmpty(String c, ApiException e) {
        if (c == null || c.isEmpty()) throw e;
    }

    public static void assertEmpty(String c, ApiException e) {
        if (c != null && !c.isEmpty()) throw e;
    }

    public static <T> void assertEmpty(Collection<T> c, ApiException e) {
        if (c != null && !c.isEmpty()) throw e;
    }

    public static void assertEquals(Object c, Object t, ApiException e) {
        if (!c.equals(t)) throw e;
    }

    public static void assertEquals(Float c, Float t, ApiException e) {
        if (c.floatValue() != t.floatValue()) throw e;
    }

    public static void assertEquals(Long c, Long t, ApiException e) {
        if (c.longValue() != t.longValue()) throw e;
    }

    public static void assertTrue(boolean b, ApiException e) {
        if (!b) throw e;
    }

    public static <T> void assertNotNull(T c, ApiException e) {
        if (c == null) throw e;
    }

    public static <T> void assertNull(T c, ApiException e) {
        if (c != null) throw e;
    }
}
